package medium;

import java.util.Arrays;

/**
 * 2079. 给植物浇水
 * 创建时间：2024-05-17 23:17
 */
public class 给植物浇水_2079 {
    static class Solution {
        public int wateringPlants(int[] plants, int capacity) {
            int ans = 0;
            for (int i = 0; i < plants.length; ) {
                int tmp = capacity;
                int len = i + 1;
                ans += len;
                while(i < plants.length && tmp >= plants[i]) {
                    tmp -= plants[i++];
                    if (i < plants.length) {
                        len += 1;
                        ans += 1;
                    }
                }
                if (i < plants.length) {
                    ans += len - 2;
                }
            }
            return ans;
        }
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.wateringPlants(new int[]{2,2,3,3}, 5));
    }
}
